View Single Post
Old May 26th, 2006, 10:18 AM   #199
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
You can add strings together in the same way you add numbers together:
>>> 1 + 1
2
>>> "a" + "b"
"ab"
The += operator is just a shortcut. The two lines of code below mean exactly the same thing:
x = x + y
x += y
With regards to the other problem, I'll give you a brief rundown on lists and functions.

You're already a little familiar with list comprehensions. Here's some code which doubles all the numbers in a list:
numbers = [1, 2, 3, 4, 5]

doubled = [x * 2 for x in numbers]
List comprehensions are essentially a shortcut. This is how to write it out the long way round:
doubled = []
for x in numbers:
    doubled.append(x * 2)
The above code might take a little explaining. First an empty list is created called "doubled". Then, each number is multiplied by two and added to the "doubled" list. The end result is exactly the same as the list comprehension.

There is also a third way, using the map function:
def double(x):
    return x * 2
doubled = map(double, numbers)
The map function applies a function to each item in a list.

List comprehensions work well for simple operations that can fit in one line. But more complicated list comprehensions are difficult to create and to work with, so one of the other methods is better used.

What you need to do is output a list that contains both company URLs and whether a company is public or not. I suggest reading up some more on tuples and lists.
Arevos is offline   Reply With Quote