'Create dictionary out of txt file. One alphabet letter per row. Key is letter and value should be iteration of the loop
i got a problem.. I have a txt file that looks like this:
a
b
c
d
One letter per row, there is not two values per row, so nothing to split..
This code works, if I add a second value in my alphabetFile.
dict = {}
with open("alphabet.txt") as alphabetFile:
for line in alphabetFile:
(key, val) = line.split()
dict[int(key)] = val
print(dict)
But I should only have 1 value per row... Im thinking the iteration should be the second value.. but im stuck and tired.. any ideas?
Solution 1:[1]
void someFunction(List<User> users) {
// do something
}
And calling the function:
someFunction(users) ;
--
EDIT: Okay, it is specifically about a Card.
Well, depends ... if you want to somehow put all user information on one card ... But I assume you want to create a bunch of cards, one for each user?
There is a number of ways to reach that. This is one of the easiest:
for (var user in users)
Card(
child: Text('Name: ${user.name}'),
),
Solution 2:[2]
Type Inference let you send any type of data in functin Create method like this:
void card(var users) {
// Do whatever you want to do with list
}
and you can call this card method where you want like this:
card(user)
and you will be done.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | K_Chandio |
